from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-20 14:31:14.945829
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 20, Jan, 2021
Time: 14:31:18
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.3130
Nobs: 177.000 HQIC: -46.2730
Log likelihood: 1982.76 FPE: 4.16765e-21
AIC: -46.9280 Det(Omega_mle): 2.54142e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.441968 0.145494 3.038 0.002
L1.Burgenland 0.133490 0.076156 1.753 0.080
L1.Kärnten -0.233972 0.061909 -3.779 0.000
L1.Niederösterreich 0.126815 0.175250 0.724 0.469
L1.Oberösterreich 0.221310 0.150835 1.467 0.142
L1.Salzburg 0.182914 0.080023 2.286 0.022
L1.Steiermark 0.095389 0.108597 0.878 0.380
L1.Tirol 0.154775 0.072467 2.136 0.033
L1.Vorarlberg 0.013423 0.069169 0.194 0.846
L1.Wien -0.121869 0.145946 -0.835 0.404
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.501516 0.186071 2.695 0.007
L1.Burgenland 0.016435 0.097395 0.169 0.866
L1.Kärnten 0.372624 0.079174 4.706 0.000
L1.Niederösterreich 0.098254 0.224126 0.438 0.661
L1.Oberösterreich -0.172398 0.192902 -0.894 0.371
L1.Salzburg 0.184279 0.102340 1.801 0.072
L1.Steiermark 0.258593 0.138884 1.862 0.063
L1.Tirol 0.138415 0.092678 1.494 0.135
L1.Vorarlberg 0.188247 0.088460 2.128 0.033
L1.Wien -0.573082 0.186649 -3.070 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.303352 0.065119 4.658 0.000
L1.Burgenland 0.113648 0.034085 3.334 0.001
L1.Kärnten -0.024991 0.027709 -0.902 0.367
L1.Niederösterreich 0.042684 0.078437 0.544 0.586
L1.Oberösterreich 0.281292 0.067510 4.167 0.000
L1.Salzburg 0.004441 0.035816 0.124 0.901
L1.Steiermark -0.016897 0.048605 -0.348 0.728
L1.Tirol 0.093793 0.032434 2.892 0.004
L1.Vorarlberg 0.126672 0.030958 4.092 0.000
L1.Wien 0.082077 0.065321 1.257 0.209
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.209431 0.075833 2.762 0.006
L1.Burgenland -0.005936 0.039693 -0.150 0.881
L1.Kärnten 0.024651 0.032267 0.764 0.445
L1.Niederösterreich 0.025794 0.091342 0.282 0.778
L1.Oberösterreich 0.383000 0.078617 4.872 0.000
L1.Salzburg 0.094822 0.041708 2.273 0.023
L1.Steiermark 0.187994 0.056602 3.321 0.001
L1.Tirol 0.043970 0.037771 1.164 0.244
L1.Vorarlberg 0.100339 0.036052 2.783 0.005
L1.Wien -0.066364 0.076068 -0.872 0.383
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.549693 0.151057 3.639 0.000
L1.Burgenland 0.074278 0.079068 0.939 0.348
L1.Kärnten 0.006055 0.064276 0.094 0.925
L1.Niederösterreich -0.031682 0.181951 -0.174 0.862
L1.Oberösterreich 0.131945 0.156603 0.843 0.399
L1.Salzburg 0.050739 0.083082 0.611 0.541
L1.Steiermark 0.123538 0.112750 1.096 0.273
L1.Tirol 0.222175 0.075238 2.953 0.003
L1.Vorarlberg 0.017771 0.071814 0.247 0.805
L1.Wien -0.130732 0.151526 -0.863 0.388
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148895 0.107989 1.379 0.168
L1.Burgenland -0.019174 0.056525 -0.339 0.734
L1.Kärnten -0.012053 0.045950 -0.262 0.793
L1.Niederösterreich 0.138817 0.130075 1.067 0.286
L1.Oberösterreich 0.383375 0.111953 3.424 0.001
L1.Salzburg -0.025357 0.059395 -0.427 0.669
L1.Steiermark -0.029075 0.080603 -0.361 0.718
L1.Tirol 0.187458 0.053787 3.485 0.000
L1.Vorarlberg 0.047378 0.051339 0.923 0.356
L1.Wien 0.186048 0.108324 1.718 0.086
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.233090 0.135955 1.714 0.086
L1.Burgenland 0.077967 0.071163 1.096 0.273
L1.Kärnten -0.051889 0.057850 -0.897 0.370
L1.Niederösterreich -0.073335 0.163761 -0.448 0.654
L1.Oberösterreich -0.092789 0.140946 -0.658 0.510
L1.Salzburg 0.033287 0.074776 0.445 0.656
L1.Steiermark 0.379441 0.101477 3.739 0.000
L1.Tirol 0.505062 0.067716 7.459 0.000
L1.Vorarlberg 0.194530 0.064634 3.010 0.003
L1.Wien -0.203183 0.136377 -1.490 0.136
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.114384 0.158046 0.724 0.469
L1.Burgenland 0.017757 0.082726 0.215 0.830
L1.Kärnten -0.105690 0.067250 -1.572 0.116
L1.Niederösterreich 0.243210 0.190369 1.278 0.201
L1.Oberösterreich 0.024981 0.163848 0.152 0.879
L1.Salzburg 0.218549 0.086926 2.514 0.012
L1.Steiermark 0.126811 0.117966 1.075 0.282
L1.Tirol 0.098633 0.078719 1.253 0.210
L1.Vorarlberg 0.022201 0.075137 0.295 0.768
L1.Wien 0.248074 0.158537 1.565 0.118
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.577675 0.086714 6.662 0.000
L1.Burgenland -0.020126 0.045389 -0.443 0.657
L1.Kärnten -0.000854 0.036897 -0.023 0.982
L1.Niederösterreich -0.042000 0.104449 -0.402 0.688
L1.Oberösterreich 0.280389 0.089897 3.119 0.002
L1.Salzburg 0.014396 0.047693 0.302 0.763
L1.Steiermark 0.016935 0.064724 0.262 0.794
L1.Tirol 0.073264 0.043190 1.696 0.090
L1.Vorarlberg 0.165789 0.041225 4.022 0.000
L1.Wien -0.061335 0.086983 -0.705 0.481
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.151268 -0.007614 0.214736 0.257474 0.068595 0.082778 -0.073251 0.158727
Kärnten 0.151268 1.000000 0.013435 0.193766 0.159783 -0.111305 0.168557 0.025588 0.313384
Niederösterreich -0.007614 0.013435 1.000000 0.288209 0.081939 0.229828 0.125083 0.060121 0.356949
Oberösterreich 0.214736 0.193766 0.288209 1.000000 0.293321 0.311739 0.086905 0.077866 0.124324
Salzburg 0.257474 0.159783 0.081939 0.293321 1.000000 0.162052 0.069198 0.073000 -0.015485
Steiermark 0.068595 -0.111305 0.229828 0.311739 0.162052 1.000000 0.116167 0.082599 -0.091905
Tirol 0.082778 0.168557 0.125083 0.086905 0.069198 0.116167 1.000000 0.146480 0.141769
Vorarlberg -0.073251 0.025588 0.060121 0.077866 0.073000 0.082599 0.146480 1.000000 0.087850
Wien 0.158727 0.313384 0.356949 0.124324 -0.015485 -0.091905 0.141769 0.087850 1.000000